@echo off
setlocal enabledelayedexpansion

set "oldPath=C:\NodeVersionPackages\node-v16.13.0-win-x64"
set "newPath=C:\NodeVersionPackages\node-v16.20.0-win-x64"

set "updatedPath="
for %%A in ("%PATH:;=","%") do (
    if /I "%%~A"=="%oldPath%" (
        set updatedPath=!updatedPath!;%newPath%
    ) else (
        set updatedPath=!updatedPath!;%%~A
    )
)

setx PATH "!updatedPath:~1!" /m

endlocal

REM 删除系统 PATH 变量中包含 'node' 的所有条目

set "pathVar=%PATH%"
set "newPathVar="

:checkNode
for %%B in ("%pathVar:;=","%") do (
    set "currentPath=%%~B"
    if /I not "!currentPath:node=!"=="!currentPath!" (
        rem If the current path contains 'node', do nothing (skip it)
    ) else (
        set "newPathVar=!newPathVar!;%%~B"
    )
)

if not "%newPathVar%"=="" (
    setx PATH "!newPathVar:~1!" /m
)


%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit
